c# .net

How to create a web application performance monitoring download speed test .Net?

How to create a web application performance monitoring download speed test .Net? , someone asked me to explain?

In this article I will show you how to create a web application to check the speed of downloading files in asp.net c#.

You can find out the time required to download a file. Here I used to download a jQuery script file from Google CDN and calculate the speed based on the download start and end time. 

 

DownloadSpeed.aspx: 

 

<form id="form1" runat="server">
         <div  style="border: 1px solid #357ae8; padding:15px 15px 15px 15px ; width: 400px; height: 250px">
             <h2>Monitoringdownload speed of file </h2>
            <asp:Label ID="lblDownloadSpeed" runat="server" />
            <asp:Button ID="btnCheckSpeed" Text="Check Speed" runat="server" OnClick="DownloadSpeed" />
        </div>
    </form>

Code Behind DownloadSpeed.aspx.cs:

 

protected void DownloadSpeed(object sender, EventArgs e)
    {
        double[] speeds = new double[5];
        for (int i = 0; i < 5;i++)
        {
            int jQueryFileSize = 261; //Size of google cdn JQuery File in KB.
            WebClient client = new WebClient();
            DateTime startTime = DateTime.Now;
           client.DownloadFile("http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.js", Server.MapPath("~/jQuery.js"));
            DateTime endTime = DateTime.Now;
           speeds[i] = Math.Round((jQueryFileSize / (endTime- startTime).TotalSeconds));
        }
       lblDownloadSpeed.Text = string.Format("Download Speed:{0}KB/s",speeds.Average());
    }

 

Output:

web application performance monitoring

Post your comments / questions